<template>
    <div class="refund">
        <el-form :inline="true" :model="formInline">
        <el-form-item label="地区">
            <el-input v-model="formInline.city" placeholder="地区" @keyup.enter.native="search"></el-input>
        </el-form-item>
        <el-form-item label="昵称">
            <el-input v-model="formInline.station_id" placeholder="关键字" @keyup.enter.native="search"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="search">搜索</el-button>
            <el-button type="primary" @click="reset">重置</el-button>
        </el-form-item>
        </el-form>
        <el-table
            :header-cell-style="{color:'#555555'}"
            class="black"
            :data="tableData"
            stripe
            border
            style="width: 100%">
            <el-table-column
                prop="id"
                label="id"
                align="center">
            </el-table-column>
            <el-table-column
                prop="create_time"
                label="创建时间"
                align="center">
            </el-table-column>
            <el-table-column
                prop="city"
                label="城市"
                align="center">
            </el-table-column>
            <el-table-column
                prop="state"
                label="定金状态"
                align="center">
            </el-table-column>
            <el-table-column
                prop="restart_time"
                label="状态更新时间"
                align="center">
            </el-table-column>
            <el-table-column
                prop="man_nickname"
                label="男士用户"
                align="center">
            </el-table-column>
            <el-table-column
                prop="woman_nickname"
                label="女士用户"
                align="center">
            </el-table-column>
            <el-table-column
                prop="money"
                label="金额"
                align="center">
            </el-table-column>
            <el-table-column
                prop="man_complain"
                label="男士申诉"
                align="center">
            </el-table-column>
            <el-table-column
                prop="woman_complain"
                label="女士申诉"
                align="center">
            </el-table-column>
            <el-table-column label="操作" align="center" width="200">
                <template slot-scope="scope">
                    <el-button @click="onEditClick(scope.row)" size="small">男士胜诉</el-button>
                    <el-button @click="onDelClick(scope.row)" size="small">女士胜诉</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="footer-page">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="page_size"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total_page">
            </el-pagination>
        </div>
        <el-dialog
            title="提示"
            :visible.sync="dialogVisible"
            width="30%">
            <span>确认胜诉结果吗？</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="onSureClick">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: 'withdraw-hadle',
    data () {
        return {
            dialogVisible: false,
            del_station_id: '',
            list_params: {
                id: '',
                fuzzy_keyword: '',
                type: '',
                page: 1,
                page_size: 10
            },
            page: 1,
            page_size: 10,
            total_page: 0,
            formInline: {
                station_id: '',
                station_name: '',
                station_state: ''
            },
            tableData: [{
                id: '30212078', // 站点ID
                create_time: '20181101', // 创建时间
                city: '北京', // 站点名称
                state: '退款待制裁', // 结果状态
                restart_time: '20181212', // 状态更新时间
                man_nickname: '大菠萝', // 网站类型
                woman_nickname: '露露', // 网站类型
                money: '200', // 创建时间
                man_complain: '查看', // 网站类型
                woman_complain: '查看' // 网站类型
            }, {
                id: '30212078', // 站点ID
                create_time: '20181101', // 创建时间
                city: '北京', // 站点名称
                state: '退款待制裁', // 结果状态
                restart_time: '20181212', // 状态更新时间
                man_nickname: '大菠萝', // 网站类型
                woman_nickname: '露露', // 网站类型
                money: '200', // 创建时间
                man_complain: '查看', // 网站类型
                woman_complain: '查看' // 网站类型
            }, {
                id: '30212078', // 站点ID
                create_time: '20181101', // 创建时间
                city: '北京', // 站点名称
                state: '退款待制裁', // 结果状态
                restart_time: '20181212', // 状态更新时间
                man_nickname: '大菠萝', // 网站类型
                woman_nickname: '露露', // 网站类型
                money: '200', // 创建时间
                man_complain: '查看', // 网站类型
                woman_complain: '查看' // 网站类型
            } ]
        }
    },
    created () {
        // this.tableData = []
    },
    mounted () {
        // 进来页面获取课程
        // this.getList(this.list_params)
    },
    methods: {
        onAddKeywordClick () {
            this.$router.push({
                name: 'monitorSet.keyword.sourceAdd',
                params: {
                // course_id: this.courseList[index].id
                }
            })
        },
        search () {
            this.page = 1
            this.list_params = {
                id: this.formInline.station_id,
                fuzzy_keyword: this.formInline.station_name,
                type: this.formInline.station_state,
                page: this.page,
                page_size: this.page_size
            }
            // 进来页面获取课程
            this.getList(this.list_params)
        },
        reset () {
            this.formInline = {
                station_id: '',
                station_name: '',
                station_url: '',
                station_state: '',
                station_code: ''
            }
        },
        onEditClick (row) {
            this.$router.push({
                name: 'monitorSet.keyword.sourceEdit',
                params: {
                    id: row.station_id
                }
            })
        },
        onDelClick (item) {
            this.dialogVisible = true
            this.del_station_id = item.station_id
        },
        onSureClick () {
            this.dialogVisible = false
            this.deleteData(this.del_station_id)
        },
        onLimitClick () {
            console.log('禁用')
        },
        handleSizeChange (val) {
            this.page_size = val
            this.list_params.page_size = val
            // this.page = 1
            // this.list_params.page = 1
            this.getList(this.list_params)
        },
        handleCurrentChange (val) {
            this.page = val
            this.list_params.page = val
            this.getList(this.list_params)
        },
        getList (data) {
            this.$api.keyword.getList(data, res => {
                // 隐藏加载动画
                // this.$vux.loading.hide()
                if (res.code === 200) {
                    this.tableData = this.getDetail(res.data.data)
                    this.total_page = res.data.total
                    console.log(this.tableData)
                }
            })
        },
        getDetail (list) {
            let data = list || []
            let newArry = []
            for (let i = 0; i < data.length; i++) {
                newArry.push({
                    station_id: data[i].id || '',
                    station_name: data[i].keyword || '',
                    station_state: data[i].type === 'positive' ? '正面' : '负面',
                    station_create: data[i].created_at || ''
                })
                if (i === data.length - 1) {
                    return (newArry)
                }
            }
        },
        deleteData (id) {
            this.$api.keyword.deleteData(id, res => {
                // 隐藏加载动画
                // this.$vux.loading.hide()
                if (res.code === 200) {
                    this.getList(this.list_params)
                }
            })
        }
    }
}
</script>

<style lang="less" scoped>
    .refund {
        position: relative;
        width: 100%;
        height: 100%;
        .margin-bottom-12 {
            margin-bottom: 10px;
        }
        .el-row {
            margin-bottom: 20px;
            &:last-child {
                margin-bottom: 0;
            }
        }
        .el-col {
            border-radius: 4px;
        }
        .grid-content {
            position: relative;
            height: 40px;
        }
        .grid-padding {
            /* padding-left: 20px; */
            padding-right: 20px;
        }
        .grid-title {
            float: left;
            width: 72px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            color: #333;
            text-align: center;
        }
        .grid-input {
            float: left;
            width: 130px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            color: #333;
            text-align: center;
        }
        .row-bg {
            padding: 10px 0;
            background-color: #f9fafc;
        }
        .footer-page {
            width: 540px;
            margin: 0 auto;
            padding-top: 20px;
        }
    }
</style>
